package com.demo4;

import com.demo4.exception.ArgementErrorException;
import com.demo4.exception.MinusArgementException;

import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * <pre>
 * - 图形的抽象类
 * Author : J.L.Zhou
 * E-Mail : 2233875735@qq.com
 * Tel : 151 1104 7708
 * Date : 2021-04-08 9:51
 * Version : 1.0
 * Copyright 2021 jlzhou.top Inc. All rights reserved.
 * Warning: this content is only for internal circulation of the company.
 *          It is forbidden to divulge it or use it for other commercial purposes.
 * </pre>
 **/
public abstract class AbstractShape implements IShape {

  private String name;

  /**
   * 周长
   */
  protected float perimeter;

  /**
   * 面积
   */
  protected float area;

  public AbstractShape(String name){
    this.name = name;
  }

  public final void input(Scanner sc){
    try {
      inputBaseInfo(sc);
    }catch (InputMismatchException e1) {
      System.out.println("输入的参数格式不正确");
      sc.next();
      input(sc);
    }catch (Exception e){
      System.out.println("输入错误:"+e.getMessage());
      input(sc);
    }
    perimeter = caclPerimeter();
    area = calcArea();
  }

  public abstract void inputBaseInfo(Scanner sc)throws MinusArgementException, ArgementErrorException;
  public abstract float calcArea();
  public abstract float caclPerimeter();

  /**
   * 获取周长
   * @return 周长
   */
  public final float getPerimeter(){
    return perimeter;
  }


  /**
   * 获取面积
   * @return
   */
  public final float getArea(){
    return area;
  }

  /**
   * 打印基本信息
   */
  public final void show() {
    System.out.format("%-3s\t周长：%.2f\t面积：%.2f\t%s\n",getName(),perimeter,area,getBaseInfo());
  }

  public abstract String getBaseInfo();

  public final String getName() {
    return name;
  }
}
